package a_erfenchazhao;

import java.util.Arrays;

/**
 * @ClassName TestArraysBinarySearch
 * @Description
 * @Author Zhang Li Tao
 * @Date 2024/3/17
 * @Version 1.0
 **/
public class D_TestArraysBinarySearch {
    public static void main(String[] args) {
        int[] array = {1, 2, 3, 4, 5, 6, 7, 8};
        int target = 0;

        // 目标索引位置
        int index = Arrays.binarySearch(array, target);
        System.out.println(index);

        // 如果没找的话 理应插入位置
        if (index < 0) {
            System.out.println(Math.abs(index + 1));
        }
    }
}
